package com.ydjk.framework.web.service;

import com.ydjk.common.core.domain.entity.ComUser;
import com.ydjk.common.core.domain.model.LoginUser;
import com.ydjk.system.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 用户验证处理
 *
 * @author xqs
 */
@Service("userDetailsByWeChatServiceImpl")
public class UserDetailsByWeChatServiceImpl implements UserDetailsService {
    private static final Logger log = LoggerFactory.getLogger(UserDetailsByWeChatServiceImpl.class);

    @Autowired
    private IUserService userService;

    @Override
    public UserDetails loadUserByUsername(String openid) throws UsernameNotFoundException {
        ComUser param = new ComUser();
        param.setOpenId(openid);
        ComUser user = userService.selectJkUserByCondition(param);
        return createLoginUser(user);
    }

    public UserDetails createLoginUser(ComUser user) {
        return new LoginUser(user);
    }
}
